Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Graphics /
Chapter 4 - Geometric Operations / Using Geometric Operations


Determining Whether One Shape Contains Another

QuickDraw GX also provides three functions to help you determine whether one area contains another:

The sample function in Listing 4-11 creates a small circular path and a larger, donut-shaped path to test for containment.

Listing 4-11 Creating a path shape with two contours and a smaller concentric rectangle shape

void CreateMultiplePaths(void)
{
   gxShape twoCircleShape, smallSquareShape;

   static rectangle smallSquareGeometry[] = {ff(90), ff(90),
                                             ff(110), ff(110)};


   static long twoCircleGeometry[] = {2, /* # of contours */
                                      4, /* # of points */
                                      0xF0000000, /* 1111 ... */
                                      ff(50), ff(50),    
                                      ff(150), ff(50), 
                                      ff(150), ff(150),  
                                      ff(50), ff(150),
                                      4, /* # of points */
                                      0xF0000000, /* 1111 ... */
                                      ff(65), ff(65),
                                      ff(65), ff(135) ,
                                      ff(135), ff(135),
                                      ff(135), ff(65)};


   twoCircleShape = GXNewPaths((gxPaths *) twoCircleGeometry);
   GXSetShapeFill(twoCircleShape, gxEvenOddFill);
   
   smallSquareShape = GXNewRectangle(&smallSquareGeometry);
   GXSetShapeFill(smallSquareShape, gxEvenOddFill);

   GXDrawShape(twoCircleShape);
   GXDisposeShape(twoCircleShape);
   GXDrawShape(smallSquareShape);
   GXDisposeShape(smallSquareShape);
}
The results of this sample function are shown in Figure 4-50.

Figure 4-50 A path shape with two contours and a smaller concentric rectangle shape

Since the GXContainsShape function considers shape fill when calculating whether one shape contains another, the following function call:

GXContainsShape(twoCircleShape, smallerCircleShape);
returns false; the area covered by the larger path does not contain the area covered by the smaller path.

For more information about the GXContainsShape function, see page 4-103.

The functions GXContainsRectangle and GXContainsBoundsShape work similarly to the GXContainsShape function, except the input parameters to these functions are rectangle geometries, rather than shapes. The GXContainsRectangle function compares two rectangle geometries and the GXContainsBoundsShape compares a rectangle geometry to a shape.

For more information about the GXContainsRectangle function and the GXContainsBoundsShape function, see page 4-100 and page 4-101, respectively.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help